/*
绘制处理类，使用方法
import 'static/js/draw-lib/Leaflet.draw.js'
import 'static/js/draw-lib/Toolbar.js'
import 'static/js/draw-lib/Tooltip.js'

import 'static/js/draw-lib/ext/TouchEvents.js'
import 'static/js/draw-lib/ext/GeometryUtil.js'
import 'static/js/draw-lib/ext/LatLngUtil.js'
import 'static/js/draw-lib/ext/LineUtil.Intersect.js'
import 'static/js/draw-lib/ext/Polyline.Intersect.js'
import 'static/js/draw-lib/ext/Polygon.Intersect.js'

import 'static/js/draw-lib/draw/DrawToolbar.js'
import 'static/js/draw-lib/draw/handler/Draw.Feature.js'
import 'static/js/draw-lib/draw/handler/Draw.SimpleShape.js'
import 'static/js/draw-lib/draw/handler/Draw.Circle.js'
import 'static/js/draw-lib/draw/handler/Draw.Marker.js'
import 'static/js/draw-lib/draw/handler/Draw.Polyline.js'
import 'static/js/draw-lib/draw/handler/Draw.Polygon.js'
import 'static/js/draw-lib/draw/handler/Draw.Rectangle.js'

import 'static/js/draw-lib/edit/EditToolbar.js'
import 'static/js/draw-lib/edit/handler/EditToolbar.Edit.js'
import 'static/js/draw-lib/edit/handler/EditToolbar.Delete.js'
import 'static/js/draw-lib/edit/handler/Edit.Poly.js'
import 'static/js/draw-lib/edit/handler/Edit.SimpleShape.js'
import 'static/js/draw-lib/edit/handler/Edit.Circle.js'
import 'static/js/draw-lib/edit/handler/Edit.Marker.js'
import 'static/js/draw-lib/edit/handler/Edit.Rectangle.js'

import 'static/js/draw-lib/Control.Draw.js'

import mapDrawUtil from  'static/js/MapDrawUtil.js'

  mapDrawUtil.setDrawMap(mapobj);
  mapDrawUtil.initDrawFun();
 */
class MapDrawUtil {

  constructor() {
    this.drawShowPointInfoFun = "";
    this.drawCurdrawType = null;
    this.drawCurdrawState = "0";
    this.drawCurDrawLayer = null;
    this.drawCurDrawLayerD = null; //编辑时，编辑前的对象
    this.drawLayerGroup = [];
    this.drawHandMarker = null;
    this.drawHandPolyline = null;
    this.drawHandCircle = null;
    this.drawHandRect = null;
    this.drawHandPolygon = null;
    this.drawMap = null;
    this.drawStyleColor = "#000000"; //e60012
    this.drawStyleWidth = 1;
    this.drawStyleOpacity = 1;
    this.drawStyleFillColor = "#e7e3c0"; //cbcabe null
    this.drawStyleFillOpacity = 0.7;
    this.setDrawMap = this.setDrawMap.bind(this);
    this.drawCheck = this.drawCheck.bind(this);
    this.drawMarker = this.drawMarker.bind(this);
    this.drawPolyline = this.drawPolyline.bind(this);
    this.drawCircle = this.drawCircle.bind(this);
    this.drawRect = this.drawRect.bind(this);
    this.drawPolygon = this.drawPolygon.bind(this);
    this.setCircleRadis = this.setCircleRadis.bind(this);
    this.selectPolygonOneMarkert = this.selectPolygonOneMarkert.bind(this);
    this.setPointInfo = this.setPointInfo.bind(this);
    this.endDraw = this.endDraw.bind(this);
    this.removeDrawFun = this.removeDrawFun.bind(this);
    this.clearDrawLayer = this.clearDrawLayer.bind(this);
    this.drawCreated = this.drawCreated.bind(this);
    this.getLayerPoinInfo = this.getLayerPoinInfo.bind(this);
    this.editStart = this.editStart.bind(this);
    this.initDrawFun = this.initDrawFun.bind(this);
  }
  setDrawMap(mymap) {
    this.drawMap = mymap;
  }
  setShowPointInfo(showpointfun) {
    this.drawShowPointInfoFun = showpointfun;
  }
  getshapeLineOptions() {
    var shapeOptions = {
      stroke: true,
      color: this.drawStyleColor,
      weight: this.drawStyleWidth,
      opacity: this.drawStyleOpacity,
      fill: false,
      fillColor: this.drawStyleFillColor,
      fillOpacity: 0,
      clickable: true
    };
    return shapeOptions;
  }
  getshapeOptions() {
    var shapeOptions = {
      stroke: true,
      color: this.drawStyleColor,
      weight: this.drawStyleWidth,
      opacity: this.drawStyleOpacity,
      fill: true,
      fillColor: this.drawStyleFillColor,
      fillOpacity: this.drawStyleFillOpacity,
      clickable: true
    };
    return shapeOptions;
  }
  makerIcon(){
    return L.icon({iconUrl: '/static/css/images/marker-icon.png', iconSize: [25, 41], iconAnchor: [12, 41]});
  }
  getTypeName(){
    if (this.drawCurdrawType=="marker"){
      return "点";
    }else if (this.drawCurdrawType=="polyline"){
      return "线";
    }else if (this.drawCurdrawType=="rect"){
      return "矩形";
    }else if (this.drawCurdrawType=="polygon"){
      return "面";
    }else if (this.drawCurdrawType=="circle"){
      return "圆";
    }
    return "";
  }
  initDrawFun(){
    this.drawMap.on("draw:created", event => {
      this.drawCreated(event.layer);
      //获取绘制后的坐标信息
      let pointinfo = this.getLayerPoinInfo(this.drawCurDrawLayer);
      let objinfo={};
      objinfo.id=pointinfo.id;
      objinfo.type=pointinfo.drawType;
      objinfo.points=pointinfo.points;
      objinfo.typeName=this.getTypeName();
      this.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});

      //mapDrawUtil.endDraw();
      this.editStart();
      if (this.drawCurdrawType == "polyline" || this.drawCurdrawType == "circle" || this.drawCurdrawType == "rect" || this.drawCurdrawType == "polygon") {
        this.drawCurDrawLayer.on('edit', function () {
          var pointinfo = this.mapDrawUtilObj.getLayerPoinInfo(this.mapDrawUtilObj.drawCurDrawLayer); //获取绘制后的坐标信息
          let objinfo={};
          objinfo.id=pointinfo.id;
          objinfo.type=pointinfo.drawType;
          objinfo.points=pointinfo.points;
          objinfo.typeName=this.mapDrawUtilObj.getTypeName();
          this.mapDrawUtilObj.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});
        });
      } else if (this.drawCurdrawType == "marker") {
        //老版本插件用edit，新版本插件用drag
        //this.drawCurDrawLayer.on('edit', function () { //特别说明，修改Edit.Marker.js，在_onDragEnd函数中this._map.fire('draw:editmove', {layer: layer});下面增加一行this.fire('edit', {layer: layer});
        this.drawCurDrawLayer.on('drag', function () { //特别说明，修改Edit.Marker.js，在_onDragEnd函数中this._map.fire('draw:editmove', {layer: layer});下面增加一行this.fire('edit', {layer: layer});
          var pointinfo = this.mapDrawUtilObj.getLayerPoinInfo(this.mapDrawUtilObj.drawCurDrawLayer);  //获取绘制后的坐标信息
          let objinfo={};
          objinfo.id=pointinfo.id;
          objinfo.type=pointinfo.drawType;
          objinfo.points=pointinfo.points;
          objinfo.typeName=this.mapDrawUtilObj.getTypeName();
          this.mapDrawUtilObj.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});
        });
      }
    });
  }
  drawCheck() {
    if (this.drawMap == null) {
      alert("请设置地图对象！");
      return false;
    }
    if (this.drawCurdrawState == "1") {
      alert("已经处于绘制状态！");
      return false;
    }
    return true;
  }
  drawMarker() {
    if (!this.drawCheck()) {
      return;
    }
    this.disableHandle();
    this.drawCurdrawType = "marker";
    if (this.drawHandMarker == null) {
      this.drawHandMarker = new L.Draw.Marker(this.drawMap, null);
    }
    this.drawHandMarker.enable();
  }
  drawPolyline() {
    if (!this.drawCheck()) {
      return;
    }
    this.disableHandle();
    this.drawCurdrawType = "polyline";
    var options_polyline = {};
    options_polyline.shapeOptions = this.getshapeLineOptions();
    options_polyline.showRadius = true;
    options_polyline.metric = true;
    options_polyline.feet = true;
    if (this.drawHandPolyline == null) {
      this.drawHandPolyline = new L.Draw.Polyline(this.drawMap, options_polyline);
    }
    this.drawHandPolyline.enable();
  }

  drawCircle() {
    if (!this.drawCheck()) {
      return;
    }
    this.disableHandle();
    this.drawCurdrawType = "circle";
    let options_circle = {};
    options_circle.shapeOptions = this.getshapeOptions();
    options_circle.showRadius = true;
    options_circle.metric = true;
    options_circle.feet = true;
    if (this.drawHandCircle == null) {
      this.drawHandCircle = new L.Draw.Circle(this.drawMap, options_circle);
    }
    this.drawHandCircle.enable();
  }

  drawRect() {
    if (!this.drawCheck()) {
      return;
    }
    this.disableHandle();
    this.drawCurdrawType = "rect";
    var options_rect = {};
    options_rect.shapeOptions = this.getshapeOptions();
    options_rect.metric = true;
    if (this.drawHandRect == null) {
      this.drawHandRect = new L.Draw.Rectangle(this.drawMap, options_rect);
    }
    this.drawHandRect.enable();
  }

  drawPolygon() {
    if (!this.drawCheck()) {
      return;
    }
    this.disableHandle();
    this.drawCurdrawType = "polygon";
    var options_polygon = {};
    options_polygon.shapeOptions = this.getshapeOptions();
    options_polygon.metric = true;
    if (this.drawHandPolygon == null) {
      this.drawHandPolygon = new L.Draw.Polygon(this.drawMap, options_polygon);
    }
    this.drawHandPolygon.enable();
  }
  //编辑一个对象，需要的数据格式如下：所有外层如果做标注的管理时，存储时尽量存储成这样的格式
  /*
点：
      oneobj.id = 123;
      oneobj.type = "marker";
      oneobj.points = [23.1,121.2];
线：
      oneobj.id = 123;
      oneobj.type="polyline";
      oneobj.points=[[23.1,121.2],[23.1,121.2],[23.1,121.2]];
矩形：
      oneobj.id = 123;
      oneobj.type = "rect";
      oneobj.points=[[23.1,121.2],[23.1,121.2]]; //分别为左下  右上 坐标
面：
      oneobj.id = 123;
      oneobj.type="polygon";
      oneobj.points=[[23.1,121.2],[23.1,121.2],[23.1,121.2]];
圆：
      oneobj.id = 123;
      oneobj.type="circle";
      oneobj.points=[[23.2,121.2],12345];//[23.2,121.2] 圆中心点，12345 半径
   */
  editLayer(objinfo){
    if (!this.drawCheck()) {
      return;
    }
    this.drawCurdrawState = "1";
    this.drawCurdrawType = objinfo.type;
    if (this.drawCurdrawType=="marker"){
      let icon=this.makerIcon();
      let latlng = L.latLng(objinfo.points[0], objinfo.points[1]);
      let lmarkerOption = {
        draggable: false,
        rotationAngle: 0, //方向，正北是0，顺时针，共360
        icon,
        data: objinfo	 //为了在点击时能获取到相关的信息
      };
      this.drawCurDrawLayer=new L.marker(latlng, lmarkerOption);
      this.drawCurDrawLayer.id=objinfo.id;
      this.drawCurDrawLayer.addTo(this.drawMap);
      this.drawCurDrawLayer.editing.enable();

      this.drawCurDrawLayerD=new L.marker(latlng, lmarkerOption);
      this.drawCurDrawLayerD.id=objinfo.id;
    }else if (this.drawCurdrawType=="polyline"){
      var shapeOptions = this.getshapeLineOptions();
      this.drawCurDrawLayer=new L.Polyline(objinfo.points,shapeOptions);
      this.drawCurDrawLayer.id=objinfo.id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawCurDrawLayer.addTo(this.drawMap);
      this.drawCurDrawLayer.editing.enable();

      this.drawCurDrawLayerD=new L.Polyline(objinfo.points,shapeOptions);
      this.drawCurDrawLayerD.id=objinfo.id;
      if (this.drawCurDrawLayerD.options.editing==null){
        this.drawCurDrawLayerD.options.editing={};
      }
      if (this.drawCurDrawLayerD.options.original==null){
        this.drawCurDrawLayerD.options.original={};
      }
    }else if (this.drawCurdrawType=="rect"){
      var corner1 = L.latLng(objinfo.points[0][0],objinfo.points[0][1]); //左下
      var corner2 = L.latLng(objinfo.points[1][0],objinfo.points[1][1]); //右上
      var bounds = L.latLngBounds(corner1, corner2);
      var shapeOptions = this.getshapeOptions();
      this.drawCurDrawLayer=new L.Rectangle(bounds, shapeOptions);
      this.drawCurDrawLayer.id=objinfo.id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawCurDrawLayer.addTo(this.drawMap);
      this.drawCurDrawLayer.editing.enable();

      this.drawCurDrawLayerD=new L.Rectangle(bounds, shapeOptions);
      this.drawCurDrawLayerD.id=objinfo.id;
      if (this.drawCurDrawLayerD.options.editing==null){
        this.drawCurDrawLayerD.options.editing={};
      }
      if (this.drawCurDrawLayerD.options.original==null){
        this.drawCurDrawLayerD.options.original={};
      }
    }else if (this.drawCurdrawType=="polygon"){
      var shapeOptions = this.getshapeOptions();
      this.drawCurDrawLayer=new L.Polygon(objinfo.points,shapeOptions);
      this.drawCurDrawLayer.id=objinfo.id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawCurDrawLayer.addTo(this.drawMap);
      this.drawCurDrawLayer.editing.enable();

      this.drawCurDrawLayerD=new L.Polygon(objinfo.points,shapeOptions);
      this.drawCurDrawLayerD.id=objinfo.id;
      if (this.drawCurDrawLayerD.options.editing==null){
        this.drawCurDrawLayerD.options.editing={};
      }
      if (this.drawCurDrawLayerD.options.original==null){
        this.drawCurDrawLayerD.options.original={};
      }
    }else if (this.drawCurdrawType=="circle"){
      let shapeOptions = this.getshapeOptions();
      let latlng = L.latLng(objinfo.points[0][0], objinfo.points[0][1]);
      this.drawCurDrawLayer=new L.Circle(latlng,objinfo.points[1],shapeOptions);
      this.drawCurDrawLayer.id=objinfo.id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawCurDrawLayer.addTo(this.drawMap);
      this.drawCurDrawLayer.editing.enable();

      this.drawCurDrawLayerD=new L.Circle(objinfo.points[0],objinfo.points[1],shapeOptions);
      this.drawCurDrawLayerD.id=objinfo.id;
      if (this.drawCurDrawLayerD.options.editing==null){
        this.drawCurDrawLayerD.options.editing={};
      }
      if (this.drawCurDrawLayerD.options.original==null){
        this.drawCurDrawLayerD.options.original={};
      }
    }
    this.drawCurDrawLayer.mapDrawUtilObj=this;

    if (this.drawCurdrawType == "polyline" || this.drawCurdrawType == "circle" || this.drawCurdrawType == "rect" || this.drawCurdrawType == "polygon") {
      this.drawCurDrawLayer.on('edit', function () {
        var pointinfo = this.mapDrawUtilObj.getLayerPoinInfo(this.mapDrawUtilObj.drawCurDrawLayer); //获取绘制后的坐标信息
        let objinfo={};
        objinfo.id=pointinfo.id;
        objinfo.type=pointinfo.drawType;
        objinfo.points=pointinfo.points;
        objinfo.typeName=this.mapDrawUtilObj.getTypeName();
        this.mapDrawUtilObj.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});
      });
    } else if (this.drawCurdrawType == "marker") {
      //this.drawCurDrawLayer.on('edit', function () { //特别说明，修改Edit.Marker.js，在_onDragEnd函数中this._map.fire('draw:editmove', {layer: layer});下面增加一行this.fire('edit', {layer: layer});
      this.drawCurDrawLayer.on('drag', function () { //特别说明，修改Edit.Marker.js，在_onDragEnd函数中this._map.fire('draw:editmove', {layer: layer});下面增加一行this.fire('edit', {layer: layer});
        var pointinfo = this.mapDrawUtilObj.getLayerPoinInfo(this.mapDrawUtilObj.drawCurDrawLayer);  //获取绘制后的坐标信息
        let objinfo={};
        objinfo.id=pointinfo.id;
        objinfo.type=pointinfo.drawType;
        objinfo.points=pointinfo.points;
        objinfo.typeName=this.mapDrawUtilObj.getTypeName();
        this.mapDrawUtilObj.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});
      });
    }
  }
  setCircleRadis(ra) {
    this.drawCurDrawLayer.editing.disable();
    this.drawCurDrawLayer.setRadius(ra);
    this.drawCurDrawLayer.editing.enable();
  }

  selectPolygonOneMarkert(data) {
    if (this.drawCurdrawType == "polygon" && this.drawCurDrawLayer != null) {
      this.drawCurDrawLayer.fire("userdefine_selectonemarkert", data);
    }
  }

  setPointInfo(pointdata) {
    if (this.drawCurdrawType == "polyline") {
      //pointdata格式必须是：[[23,111],[24,112],[25,113],[23,116]]
      //[[38.117,122.7337],[38.0391,123.1347],[38.2249,123.4863]]
      this.drawCurDrawLayer.editing.disable();
      this.drawMap.removeLayer(this.drawCurDrawLayer);
      let id=this.drawCurDrawLayer.id;
      this.drawCurDrawLayer = null;
      var shapeOptions = this.getshapeLineOptions();
      this.drawCurDrawLayer = new L.polyline(pointdata, shapeOptions);
      this.drawCurDrawLayer.id=id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawMap.addLayer(this.drawCurDrawLayer);
      this.drawCurDrawLayer.editing.enable();
    } else if (this.drawCurdrawType == "circle") {
      //var latlng = L.latLng(cplat, cplng);
      this.drawCurDrawLayer.editing.disable();
      this.drawCurDrawLayer.setLatLng(pointdata);
      this.drawCurDrawLayer.editing.enable();
    } else if (this.drawCurdrawType == "rect") {
      //pointdata格式：[[40.712,114.227],[40.774,115.125]] 分别为左下  右上
      var corner1 = L.latLng(pointdata[0][0],pointdata[0][1]); //左下
      var corner2 = L.latLng(pointdata[1][0],pointdata[1][1]); //右上
      var bounds = L.latLngBounds(corner1, corner2);
      this.drawCurDrawLayer.editing.disable();
      this.drawCurDrawLayer.setBounds(bounds);
      this.drawCurDrawLayer.editing.enable();
    } else if (this.drawCurdrawType == "polygon") {
      //pointdata格式必须是：[[23,111],[24,112],[25,113],[23,116]]
      this.drawCurDrawLayer.editing.disable();
      this.drawMap.removeLayer(this.drawCurDrawLayer);
      let id=this.drawCurDrawLayer.id;
      this.drawCurDrawLayer = null;
      var shapeOptions = this.getshapeOptions();
      this.drawCurDrawLayer = new L.polygon(pointdata, shapeOptions);
      this.drawCurDrawLayer.id=id;
      if (this.drawCurDrawLayer.options.editing==null){
        this.drawCurDrawLayer.options.editing={};
      }
      if (this.drawCurDrawLayer.options.original==null){
        this.drawCurDrawLayer.options.original={};
      }
      this.drawMap.addLayer(this.drawCurDrawLayer);
      this.drawCurDrawLayer.editing.enable();
    }else if (this.drawCurdrawType == "marker") {
      //pointdata格式：[23.2,121,1]
      var latlng = L.latLng(pointdata[0], pointdata[1]);
      this.drawCurDrawLayer.setLatLng(latlng);
    }

    if (this.drawCurdrawType=="polyline" || this.drawCurdrawType=="polygon"){
        this.drawCurDrawLayer.mapDrawUtilObj=this;
        this.drawCurDrawLayer.on('edit', function () {
        var pointinfo = this.mapDrawUtilObj.getLayerPoinInfo(this.mapDrawUtilObj.drawCurDrawLayer); //获取绘制后的坐标信息
        let objinfo={};
        objinfo.id=pointinfo.id;
        objinfo.type=pointinfo.drawType;
        objinfo.points=pointinfo.points;
        objinfo.typeName=this.mapDrawUtilObj.getTypeName();
         this.mapDrawUtilObj.drawMap.fire('showDrawPoint',{'drawInfo':objinfo});
      });
    }

  }

  delLayer(id){
    if (this.drawLayerGroup!=null & this.drawLayerGroup.length>0){
      var newGroup=[];
      var dellayer=null;
      for (let k=0;k<this.drawLayerGroup.length;k++){
        if (this.drawLayerGroup[k].id==id){
          dellayer=this.drawLayerGroup[k];
        }else{
          newGroup.push(this.drawLayerGroup[k]);
        }
      }
      this.drawLayerGroup=newGroup;
      if (dellayer!=null){
        this.drawMap.removeLayer(dellayer);
      }
    }
  }

  endDraw() {
   this.endDrawNotAddGroupAndShow(false);

    if (this.drawCurDrawLayer != null) {
      this.delLayer(this.drawCurDrawLayer.id);
      this.drawMap.removeLayer(this.drawCurDrawLayer);
      this.drawLayerGroup.push(this.drawCurDrawLayer);
      this.drawMap.addLayer(this.drawLayerGroup[this.drawLayerGroup.length - 1]);
    }
    this.drawCurDrawLayer = null;
  }

  endDrawNotAddGroupAndShow(isSetNull) {
    this.disableHandle();
    if (this.drawCurDrawLayer != null) {
      this.drawCurDrawLayer.editing.disable();
    }
    if (isSetNull){
      if (this.drawCurDrawLayer != null) {
        this.drawMap.removeLayer(this.drawCurDrawLayer);
        this.drawCurDrawLayer = null;
      }
    }
    if (this.drawCurDrawLayerD!=null){
      //说明是直接编辑，不是绘制后编辑
      this.delLayer(this.drawCurDrawLayerD.id);
      this.drawLayerGroup.push(this.drawCurDrawLayerD);
      this.drawMap.addLayer(this.drawLayerGroup[this.drawLayerGroup.length - 1]);
    }
    this.drawCurdrawState = "0";
  }
  disableHandle(){
    if (this.drawCurdrawType == "marker") {
      if (this.drawHandMarker!=null){
        this.drawHandMarker.disable();
      }
    } else if (this.drawCurdrawType == "polyline") {
      if (this.drawHandPolyline!=null){
        this.drawHandPolyline.disable();
      }
    } else if (this.drawCurdrawType == "circle") {
      if (this.drawHandCircle!=null){
        this.drawHandCircle.disable();
      }
    } else if (this.drawCurdrawType == "rect") {
      if (this.drawHandRect!=null){
        this.drawHandRect.disable();
      }
    } else if (this.drawCurdrawType == "polygon") {
      if (this.drawHandPolygon!=null){
        this.drawHandPolygon.disable();
      }
    }
  }
  removeDrawFun() {
    this.drawMap.off("draw:created");
  }
  clearDrawLayer() {
    for (var i = 0; i < this.drawLayerGroup.length; i++) {
      this.drawMap.removeLayer(this.drawLayerGroup[i]);
    }
    this.drawLayerGroup = [];
  }
  drawCreated(layerfinidh){
    this.drawCurDrawLayerD=null;
    this.drawCurDrawLayer = layerfinidh;
    this.drawCurDrawLayer.mapDrawUtilObj=this;
    if (this.drawCurDrawLayer.options.editing==null){
      this.drawCurDrawLayer.options.editing=this.drawCurDrawLayer;
    }
    if (this.drawCurDrawLayer.options.original==null){
      this.drawCurDrawLayer.options.original={};
    }
    let timestamp = (new Date()).getTime();
    this.drawCurDrawLayer.id=timestamp.toString();
    this.drawMap.addLayer(this.drawCurDrawLayer);

    if (this.drawCurdrawType == "marker") {
      this.drawHandMarker.disable();
    } else if (this.drawCurdrawType == "polyline") {
      this.drawHandPolyline.disable();
    } else if (this.drawCurdrawType == "circle") {
      this.drawHandCircle.disable();
    } else if (this.drawCurdrawType == "rect") {
      this.drawHandRect.disable();
    } else if (this.drawCurdrawType == "polygon") {
      this.drawHandPolygon.disable();
    }
  }
  //开始编辑
  editStart(){
    if (this.drawCurdrawType == "polyline" || this.drawCurdrawType == "circle" || this.drawCurdrawType == "rect" || this.drawCurdrawType == "polygon") {
      this.drawCurDrawLayer.editing.enable();
    } else if (this.drawCurdrawType == "marker") {
      this.drawCurDrawLayer.editing.enable();
    }
    this.drawCurdrawState = "1";
  }
//获取对象的点位信息，如果是rect，返回四个坐标点的值，依次分别是：左下、右上，每个点都是个数组，数组中第一个是lat，第二个是lng
//如果是circle，则返回的数组中有两个元素，第一个是中心点坐标数组，第二个是半径值
//点的格式是：lat,lng
  getLayerPoinInfo(lay) {
    var coordinates_info_ary = [];

    var obj = lay.toGeoJSON();
    var geometry_info = obj.geometry;
    if (geometry_info.type == "Polygon") {
      var coordinates_ary_all = geometry_info.coordinates;
      if (coordinates_ary_all.length > 0) {
        var coordinates_ary = coordinates_ary_all[0];
        if (coordinates_ary.length > 0) {
          for (var k = 0; k < coordinates_ary.length - 1; k++) { //因为最后一个点和第一个点一致
            var onepoint = coordinates_ary[k];
            var onep = [];
            var tempd = onepoint[1];
            tempd = this.formatFloat(tempd, 6);
            onep.push(tempd);
            tempd = onepoint[0];
            tempd = this.formatFloat(tempd, 6);
            if (tempd > 180) {
              tempd = tempd - 180;
              tempd = 180 - tempd;
              tempd = 0 - tempd;
            }
            onep.push(tempd);
            coordinates_info_ary.push(onep);
          }
        }
      }
    } else if (geometry_info.type == "LineString") { //Polyline
      var coordinates_ary = geometry_info.coordinates;
      if (coordinates_ary.length > 0) {
        for (var k = 0; k < coordinates_ary.length; k++) {
          var onepoint = coordinates_ary[k];
          var onep = [];
          var tempd = onepoint[1];
          tempd = this.formatFloat(tempd, 6);
          onep.push(tempd);
          tempd = onepoint[0];
          tempd = this.formatFloat(tempd, 6);
          if (tempd > 180) {
            tempd = tempd - 180;
            tempd = 180 - tempd;
            tempd = 0 - tempd;
          }
          onep.push(tempd);
          coordinates_info_ary.push(onep);
        }
      }
    } else if (geometry_info.type == "Point") {
      var onepoint = geometry_info.coordinates;
      var onep = [];
      var tempd = onepoint[1];
      tempd = this.formatFloat(tempd, 6);
      coordinates_info_ary.push(tempd);
      tempd = onepoint[0];
      tempd = this.formatFloat(tempd, 6);
      if (tempd > 180) {
        tempd = tempd - 180;
        tempd = 180 - tempd;
        tempd = 0 - tempd;
      }
      coordinates_info_ary.push(tempd);

      var radius = lay._mRadius;
      if (typeof(radius) == "undefined") {
        //表示是Marker，则不不需要进行处理
      } else {
        //表示是圆
        radius = this.formatFloat(radius, 3);
        coordinates_info_ary.push(radius);
      }
    }
    let retobj={};
    retobj.points=coordinates_info_ary;
    if (this.drawCurdrawType=="rect"){
      let tempary=[];
      tempary.push(coordinates_info_ary[0]);
      tempary.push(coordinates_info_ary[2]);
      retobj.points=tempary;
    }else if (this.drawCurdrawType=="circle"){
      let tempary=[];
      tempary.push(coordinates_info_ary[0]);
      tempary.push(coordinates_info_ary[1]);
      let tempr=coordinates_info_ary[2];
      coordinates_info_ary=[];
      coordinates_info_ary.push(tempary);
      coordinates_info_ary.push(tempr);
      retobj.points=coordinates_info_ary;
    }
    retobj.id=lay.id;
    retobj.drawType=this.drawCurdrawType;
    //return coordinates_info_ary;
    return retobj;
  }
//获取圆形对象的bonds对象，结果是个数组，分别代表左下、右上的位置，每个位置是个对象，对象具有lat和lng属性
  getCircleBond() {
    var bond = this.drawCurDrawLayer.getBounds();
    var southWest = bond._southWest;
    var northEast = bond._northEast;
    var ret = [];
    ret.push(southWest);
    ret.push(northEast);
    return ret;
  }
  formatFloat(numberRound, roundDigit) { //四舍五入，保留位数为roundDigit
    if (numberRound >= 0) {
      var tempNumber = parseInt((numberRound * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
      return tempNumber;
    } else {
      var numberRound1 = -numberRound;
      var tempNumber = parseInt((numberRound1 * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
      return -tempNumber;
    }
  }

}
export default new MapDrawUtil()
